import groovy.json.JsonSlurper
import groovyx.gpars.GParsPool

import org.noria.web.util.HttpBot
import org.noria.web.util.HttpResult
import org.apache.http.entity.ContentType

def main() {
	//println 'hello'

	(1..19).toArray().each {
		//println it


		def rs = HttpBot.post('https://10.58.137.207/B1Hiring/WS/CandidateWS.asmx/GetCandidateList',
			"{\"mRequest\":{\"paging\":{\"current\":${it},\"length\":100}}}", ContentType.APPLICATION_JSON, null, null)
		assert (rs.getStatus() == 200) 

		new File("B1__201407__${it}") << rs.getBody()
		
		def cc = new JsonSlurper().parseText(rs.getBody())
		cc.d.DataRows.each {
			// https://10.58.137.207/B1Hiring/UploadFiles/Resume/635513121673569839_%E7%99%BD%E6%88%90%E5%93%B2_%E7%AE%80%E5%8E%86.docx
			if (it.CVPath) {
				def target = URLEncoder.encode(it.CVPath).replace('+', '%20')
				println "curl -k -o '${it.CVPath}' 'https://10.58.137.207/B1Hiring/UploadFiles/Resume/${target}'"
			}
		}
	}

	//return

}

main()